<@pp.dropOutputFile/>
<#include "../common/validation.ftl">
<#include "../common/util-easyui.ftl">

<#-- generate package name -->

<#-- iterate table list-->
<#list doc.tables as table>
<#assign module = doc.artifactid?replace(".", "/") + "/" + table.moduleid?uncap_first>
<#assign fileName = table.name?cap_first>
<#assign data_url = module + "/" + fileName>
<@pp.changeOutputFile name="/main/webapp/" + data_url + "/check_js.ftl"/>
<#noparse>
var $DT = [];
$(function(){
	$DT = $("#dataTable");
	init_toolbar();
	$DT.datagrid({
		fit: true,
		nowrap: true,
		striped: true,
		url:"${base}/</#noparse>${data_url}/getPage.action",
		queryParams : array2map($("#search_form").serializeArray()),
		sortName: "obj.<#if table.idFieldName??>${table.idFieldName}<#else>id</#if>",
		sortOrder: "desc",
		remoteSort: false,
		idField:"obj.<#if table.idFieldName??>${table.idFieldName}<#else>id</#if>",
		singleSelect:false,
		checkOnSelect:true,
		selectOnCheck:true,
		pageSize : 20,
		pageList:[20, 50, 100],
		frozenColumns:[[
			{field:"ck",checkbox:true},
			{title:"ID",hidden:true, field:"obj.<#if table.idFieldName??>${table.idFieldName}<#else>id</#if>",width:40,sortable:true}
		]],
		columns:[[
			{"field":"obj.sys_status", "sortable":"true", "title":"状态"}<#if (table.fields?length > 0)>,</#if>
			<#list table.fields as field>
			<#if field.name?lower_case != "id" && !field.name?starts_with("sys_")>
			{"field":"obj.${field.name}", "sortable":"true", "title":"${field.label}"}<#if field_has_next>,</#if>
			</#if>
			</#list>
			<#noparse>
		]],
		pagination : true,
		rownumbers : true,
		toolbar : "#toolbar",
		onLoadError:function(){
		},
		onLoadSuccess : function(data){
			//$(".button-edit").linkbutton({plain:true}).tooltip();
		}
	});
});
	
function init_toolbar(){
	$("#btn_reset").bind('click', doReset);
}

function doReset(){
	var rows = $("#dataTable").datagrid("getChecked");
	if(rows.length > 0){
		var items = {};
		for(var i=0;i<rows.length;i++){
			items["items[" + i + "]"] = rows[i]["obj.id"];
		}
		$.post("${base}/</#noparse>${data_url}<#noparse>/reset.action", 
			items, 
			function(data){
				if(data.success == 0){
					$("#dataTable").datagrid("reload");
				}
				showTip(data.success == 0, data.message);				
			},
			"json"
		);
	}
}

</#noparse>
</#list>